// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
// import {alert} from 'vue-strap'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'vue-awesome/icons'
import Icon from 'vue-awesome/components/Icon'
import axios from 'axios'

Vue.config.productionTip = false

Vue.use(ElementUI);
Vue.component('icon',Icon);

const whiteList = ['/home','/login','/news','/questionaire'];
router.beforeEach(function(to,from,next){
  //未登录
  if (!store.state.isLogin) {
    if (whiteList.indexOf(to.path)!==-1) {
      next();
    }else{
      next('/login');
    }
  } else {
    if (to.path === '/login') {
      next('/home');
    }
    next();
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { 
    App
   },
  template: '<App/>',
  computed:{
    isLogin(){
      return store.state.isLogin;
    }
  }
})
